package com.jiuyi.handle;

import com.jiuyi.common.R;
import com.jiuyi.exception.SystemException;
import lombok.extern.slf4j.Slf4j;

import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {

    //处理用户操作不当出现的异常
    @ExceptionHandler(SystemException.class)
    public R SystemExceptionHandler(SystemException e) {
        log.error("出现了异常! {}",e);
        return R.error(e.getMsg());
    }

    //处理系统出现的异常
    @ExceptionHandler(Exception.class)
    public R ExceptionHandler(Exception e){
        log.error("出现了异常! {}",e);
        return R.error("系统异常");
    }
}